#include "rfid.h"
#include "type.h"
RFID::RFID(QObject* parent):QObject(parent),serial(new QSerialPort(this))
{
    serial->setPortName(rfid_dev);
    serial->setDataBits(QSerialPort::Data8);
    serial->setFlowControl(QSerialPort::NoFlowControl);
    serial->setParity(QSerialPort::NoParity);
    serial->setStopBits(QSerialPort::OneStop);
      qDebug()<<"Open2";
    serial->setBaudRate(rfid_rate);
    if(!serial->open(QIODevice::ReadWrite))
        return;
    QObject::connect(serial,SIGNAL(readyRead()),this,SLOT(ReadData()));
}
RFID::~RFID(){
    //quit=true;
    serial->close();
}
QString RFID::ReadRF(){
    QString Text;
    Text=serial->readLine();
    //QString Text2=Text.mid(9,7);
    return Text;
}

void RFID::ReadData(){
    QString Text;
    txt+=serial->readLine();
    if(txt.at(txt.size()-1)=='\n'){
       rf=txt;
        // QString Text2=txt.mid(9,7);
        //qDebug()<<txt;
       // qDebug()<<Text2;
        txt.clear();
    }
}
